package com.janyee.powerdroid.http

import com.janyee.powerdroid.http.callback.BaseCallBack
import com.janyee.powerdroid.http.callback.ICallBack
import java.io.IOException

import okhttp3.Call
import okhttp3.Callback
import okhttp3.RequestBody
import okhttp3.Response

/**
 * Created by kmlixh on 2017/2/21.
 * useage:
 * PowerDroid
 */

open class Request {
    var url:String?=null
    var requestBody: RequestBody? = null
    var callback: BaseCallBack<*,*>? = null
        get() {
            if (field != null) {
                return field
            } else {
                return object : BaseCallBack<Any?, Any?>() {
                    override fun transform(response: Response?): Any? {
                        return null
                    }

                    override fun workOnBackThread(dd:Any?, e: Exception?): Any? {
                        return dd
                    }

                    override fun workOnUiThread(r: Any?) {

                    }

                    override fun handleProcessOnUiThread(v: Any?) {

                    }

                }
            }
        }
    val builder: okhttp3.Request.Builder

    init {
        builder = okhttp3.Request.Builder()
    }


    val request: okhttp3.Request
        get() {
            builder.url(url)
            if (requestBody != null) {
                return builder.post(requestBody).build()
            } else {
                return builder.build()
            }
        }


}
